﻿using UnityEngine;
using System.Collections;

namespace RichLabelSpace
{
    public class RichSpriteAnim : RichSprite
    {
        string m_prefix_sprite_name = null;
        int m_framerate = 30;
        bool m_is_loop = false;
        UISpriteAnimation m_sprite_amin = null;
        
        protected override void SetProperty(string[] property)
        {
            base.SetProperty(property);
            if (property[0].Equals("framerate"))
            {
                this.m_framerate = int.Parse(property[1]);
            }
            else if (property[0].Equals("prefix_sprite_name"))
            {
                this.m_prefix_sprite_name = property[1];
            }
            else if (property[0].Equals("loop"))
            {
                this.m_is_loop = bool.Parse(property[1]);
            }
        }

        public override void Excute()
        {
            base.Excute();
            this.m_sprite_amin.namePrefix = this.m_prefix_sprite_name;
            this.m_sprite_amin.framesPerSecond = this.m_framerate;
            this.m_sprite_amin.loop = this.m_is_loop;
            //this.m_sprite_amin
        }

        public RichSpriteAnim(Transform parent, RichLabelCtrl ctrl)
            : base(parent, ctrl)
        {
            if(this.m_ui_widget != null)
            {
                var go = this.m_ui_widget.gameObject;
                go.name = "RichSpriteAnim";
                go.transform.SetParent(parent);
                this.m_sprite_amin = go.AddComponent<UISpriteAnimation>();
                
            }
        }


    }
}
